﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntityModel;
using BusinessLayer;
using System.Drawing;

namespace PL___Web_Application
{
    public partial class Register : PagesMethods
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckCookie();

        }
        protected void changeform(object sender, EventArgs e)
        {
          
            if (business_rd.Checked)
            {
                register_private.Visible = false;
                register_business.Visible = true;
            }
            else
            {
                register_business.Visible = false;
                register_private.Visible = true;

            }

        }
        protected void save_Business(object sender, EventArgs e)
        {
            Business b = new Business();
            b.Customer = new Customer();
            b.Customer.username = username_b_tb.Text;
            b.Customer.password = password_b_tb.Text;
            b.b_identifier = company_id_tb.Text;
            b.company_name = company_name_tb.Text;
            b.contact_person = contact_person_tb.Text;
            b.Customer.address_c = address_b_tb.Text;
            b.Customer.phone = Convert.ToInt32(phone_b_tb.Text);
            b.fax = Convert.ToInt32(fax_tb.Text);
            b.Customer.typeCustumer = 2;
            
            try
            {
                BL controller = new BL();
                controller.saveBusinessCustomer(b);
                HttpCookie cookie = new HttpCookie("cardealer");
                Response.Cookies.Add(cookie);
                cookie["cardealer-username"] = username_tb.Text;
                cookie.Expires = DateTime.Now.AddMonths(1);
                Response.Redirect("BusinessAccount.aspx");
            }
            catch (Exception ex) { error_lb.Text = ex.Message; }
        }

        protected void save_private(object sender, EventArgs e)
        {
            Private p = new Private();
            p.Customer = new Customer();
            p.Customer.username = username_tb.Text;
            p.Customer.password = password_tb.Text;
            p.name = name_tb.Text;
            p.cpr = Convert.ToInt32(cpr_tb.Text);
            p.Customer.address_c = address_tb.Text;
            p.Customer.phone = Convert.ToInt32(phone_tb.Text);
            p.age = Convert.ToInt32(age_tb.Text);
            p.sex = sex_cb.SelectedValue;

            try
            {
                BL controller = new BL();
                controller.savePrivateCustomer(p);
                HttpCookie cookie = new HttpCookie("cardealer");
                Response.Cookies.Add(cookie);
                cookie["cardealer-username"] = username_tb.Text;
                cookie.Expires = DateTime.Now.AddMonths(1);
                Response.Redirect("PrivateAccount.aspx");
            }
            catch (Exception ex) { error_lb.Text = ex.Message; }

        }
    }
}